﻿using DI;
using Core.Dtos;
using Core.Domain;
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Core.Mappers;
using Core.IServices;
using Microsoft.AspNet.Identity;
using StructureMap;
using StructureMap.Pipeline;

namespace Tests.Services
{
    [TestClass]
    public class UserStoreServiceTest
    {
        private IUserStoreService service;

        [TestInitialize()]
        public void Init()
        {
            Bootstrapper.Init(new SingletonLifecycle());
            service = Bootstrapper.Resolve<IUserStoreService>();
        }

        [TestMethod]
        public void UserStoreService_Can_FindByNameAsync()
        {
            // Arrange 


            // Act            
            Task<UserDto> task = service.FindByNameAsync("demo");
            task.Wait();

            // Assert            
            Assert.IsNotNull(task.Result);
        }

        [TestMethod]
        public void UserStoreService_Can_GetPasswordHashAsync()
        {
            // Arrange             
            UserDto dto = CreateDto();

            // Act            
            Task<string> task = service.GetPasswordHashAsync(dto);
            task.Wait();

            // Assert            
            Assert.IsNotNull(task.Result);
        }

        [TestMethod]
        public void UserStoreService_Can_GetRolesAsync()
        {
            // Arrange            
            UserDto dto = CreateDto();

            // Act            
            Task<IList<string>> task = service.GetRolesAsync(dto);

            // Assert            
            Assert.IsTrue(task.Result.Count > 0);
        }

        private UserDto CreateDto()
        {
            return new UserDto() { UserName = "demo", Id = "5f76d04b-8146-4e1b-96df-0dd92fd43aae", SecurityStamp = "ce430ff8-5c19-4377-81cf-27f4810b8ad4", PasswordHash = "AOwO+2Xd6Dp3kWTbeEs/twL9Da+sItbnQYnsnWcbDRFj3Cbs3lJxBaqgAr/+c4xEHw==" };
        }
    }
}
